package com.m.system.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.client.job.utils.DataResult;
import com.m.system.domain.SysMenuEntity;
import com.m.system.service.SysMenuService;
import com.m.system.service.ViewRouterService;
import com.m.utils.GlobleSysUser;
import com.m.utils.UserUtil;






/**
 * 登录的Controller
 *
 * @author monxz
 * @Date  2021年1月29日下午5:27:51
 * @Des
 *
 */
@RestController
public class LoginController {
	
	@Autowired
	private SysMenuService sysMenuService;
	
	@Autowired
	private ViewRouterService routerService;
	
	/**
	 * 获取到信息
	 * @return
	 */
	@GetMapping("/getInfo")
//	@PreAuthorize("hasAuthority('USER')")
	public DataResult  getInfo() {
		Map<String, Object>  resMap = new HashMap<>();
		GlobleSysUser globleSysUser = UserUtil.getUser(null);
		resMap.put("permissions", globleSysUser.getPermissions());
		resMap.put("roles", globleSysUser.getRoles());
		resMap.put("user", globleSysUser);
		return DataResult.buildSuccess(resMap);
	}

	/**
	 * 获取到菜单路由
	 * @return
	 */
	@GetMapping("/getRouters")
	public DataResult getRouters() {
		List<SysMenuEntity>  voList =sysMenuService.buildMenuTree(UserUtil.getUserId(null));		
		return DataResult.buildSuccess(routerService.buildMenus(voList));
	}
	
	
    
	
}
